<template>
  <div>
    <router-link to="/">
      <div class="abs">
        <span class="iconfont back-icon">&#xe658;</span>
      </div>
    </router-link>
    <div class="header" v-show="showTitle" :style="styObj">
      <router-link to="/">
        <span class="iconfont back-icon">&#xe658;</span>
      </router-link>
      <div class="titlt">景点详情</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'BannerHeader',
  data () {
    return {
      showTitle: false,
      styObj: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      let scroll = document.documentElement.scrollTop

      if (scroll > 60) {
        let opacity = scroll / 140
        opacity = opacity > 1 ? 1 : opacity
        this.styObj = {
          opacity
        }
        this.showTitle = true
      } else {
        this.showTitle = false
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    border-radius .4rem
    line-height .8rem
    text-align center
    background rgba(0,0,0,0.7)
    .back-icon
      font-size .6rem
      color #fff
  .header
    position fixed
    top 0
    left 0
    right 0
    height $headerHeight
    line-height $headerHeight
    background-color $bgcolor
    font-size .32rem
    text-align center
    color #fff
    .title
      height $headerHeight
      line-height $headerHeight
    .back-icon
      position absolute
      top 0
      left 0
      color #fff
      font-size .6rem
</style>
